﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common;

public partial class insurance_orderdetails : MemberPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin();


        if (!IsPostBack)
        {
            InitControlValuesByPost();
        }
    }

    #region 获取POST值初始化控件
    void InitControlValuesByPost()
    {
        Model.Insurance.InsurancePolicyBase _obj = BLL.Insurance.InsurancePolicyBase.GetObjById(HttpUtility.UrlDecode(RequestBase.GetQueryString("objectid")));
        #region 显示
        lblOrderDate.Text = _obj.OrderDate.ToString("yyyy-MM-dd");

        lblOrderNumber.Text = _obj.OrderNumber;

        lblOrderStatus.Text = _obj.StatusCode.ToString().Replace("-1", "已作废").Replace("0", "新增").Replace("1", "已付款").Replace("2", "已发快递");

        lblTotalAmount.Text = _obj.TotalAmount.ToString();
        lblPersonQuantity.Text = _obj.PersonQuantity.ToString();

        lblProductName.Text = _obj.ProductName;
        lblProductItemName.Text = _obj.ProductItemName;
        lblEmail.Text = _obj.Email;
        lblPhone.Text = _obj.Phone;
        lblPrice.Text = _obj.Price.ToString();
        lblStartDate.Text = _obj.GetStartDate.ToString("yyyy-MM-dd");
        lblEndDate.Text = _obj.EndDate.ToString("yyyy-MM-dd");
        lblDestination.Text = BLL.Sys.EnumItem.GetTextByValue("DestCountryName", _obj.DestCountryName);
        lblPlicyType.Text = BLL.Sys.EnumItem.GetTextByValue("CJType", _obj.CJType);

        lblTName.Text = _obj.TName;
        lblTNameEn.Text = _obj.ETName;
        lblTBirthday.Text = _obj.TBirtyday.ToString("yyyy-MM-dd");
        lblTSex.Text = _obj.TSex.Replace("1", "女").Replace("0", "男");
        lblTIDType.Text = BLL.Sys.EnumItem.GetTextByValue("IDType", _obj.TIDType);
        lblTIDNo.Text = _obj.TIDNo;
        lblTAge.Text = _obj.TAge;

        lblInvoice.Text = (_obj.Invoice) ? "是" : "否";
        lblInvoiceRecipient.Text = _obj.InvoiceRecipient;
        lblInvoicePhone.Text = _obj.InvoicePhone;
        lblInvoiceTitle.Text = _obj.InvoiceTitle;
        lblInvoiceAddress.Text = _obj.InvoiceAddress;

        lblInvoiceFee.Text = _obj.ExpressType.Replace("顺丰快递", "20.00").Replace("申通快递", "10.00");
        lblExpressType.Text = _obj.ExpressType;
        lblSalesTypeCode.Text = _obj.SalesTypeCode.ToString().Replace("1", "电子保单(PDF)").Replace("2", "纸质保单");

        txtInvoice.Value = _obj.Invoice ? "1" : "0";
        txtExpressType.Value = _obj.ExpressType;
        txtSalesTypeCode.Value = _obj.SalesTypeCode.ToString();

        PolicyholdersListDataBind(_obj); 
        #endregion
    }
    void PolicyholdersListDataBind(Model.Insurance.InsurancePolicyBase _obj)
    {
        string[] fields = new string[] { "Name", "NameEn", "IDType", "IDNo", "Sex", "Birthday", "Age" };
        string[] fieldstype = new string[] { "System.String", "System.String", "System.String", "System.String", "System.String", "System.String", "System.String" };
        DataTable dat = (new DataTableUtils()).BuildingDTStruct("PolicyholdersDAT", fields, fieldstype);

        for (int i = 0; i <= _obj.IDNo.Split(',').Length - 1; i++)
        {
            dat.Rows.Add(new object[] { 
                _obj.Name.Split(',')[i].Trim(), 
                _obj.EName.Split(',')[i].Trim(), 
                BLL.Sys.EnumItem.GetTextByValue("IDType", _obj.IDType.Split(',')[i].Trim()), 
                _obj.IDNo.Split(',')[i].Trim(),
                _obj.Sex.Split(',')[i].Trim().Replace("1", "女").Replace("0", "男"),
                _obj.Birtyday.Split(',')[i].Trim(),
                _obj.Age.Split(',')[i].Trim()
            });
        } 

        rptPolicyholders.DataSource = dat;
        rptPolicyholders.DataBind();
    }
    #endregion
}